package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ParkingCardOrder;
import com.ruoyi.dto.WeChatRefundDto;
import com.ruoyi.service.IParkingCardOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 停车卡订单Controller
 * 
 * @author dongdong
 * @date 2025-09-09
 */
@Validated
@RestController
@RequestMapping("/parking/parkingCardOrder")
public class ParkingCardOrderController extends BaseController
{
    @Autowired
    private IParkingCardOrderService parkingCardOrderService;

    /**
     * 查询停车卡订单列表
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingCardOrder parkingCardOrder)
    {
        startPage();
        List<ParkingCardOrder> list = parkingCardOrderService.selectParkingCardOrderList(parkingCardOrder);
        return getDataTable(list);
    }

    /**
     * 导出停车卡订单列表
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:export')")
    @Log(title = "停车卡订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingCardOrder parkingCardOrder)
    {
        List<ParkingCardOrder> list = parkingCardOrderService.selectParkingCardOrderList(parkingCardOrder);
        ExcelUtil<ParkingCardOrder> util = new ExcelUtil<ParkingCardOrder>(ParkingCardOrder.class);
        util.exportExcel(response, list, "停车卡订单数据");
    }

    /**
     * 获取停车卡订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parkingCardOrderService.selectParkingCardOrderById(id));
    }

    /**
     * 新增停车卡订单
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:add')")
    @Log(title = "停车卡订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingCardOrder parkingCardOrder)
    {
        return toAjax(parkingCardOrderService.insertParkingCardOrder(parkingCardOrder));
    }

    /**
     * 修改停车卡订单
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:edit')")
    @Log(title = "停车卡订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingCardOrder parkingCardOrder)
    {
        return toAjax(parkingCardOrderService.updateParkingCardOrder(parkingCardOrder));
    }

    /**
     * 删除停车卡订单
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:remove')")
    @Log(title = "停车卡订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkingCardOrderService.deleteParkingCardOrderByIds(ids));
    }

    /*
     * 退款
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCardOrder:edit')")
    @PostMapping("/refund")
    public AjaxResult refund(@RequestBody @Validated WeChatRefundDto weChatRefundDto) {
        return toAjax(parkingCardOrderService.refund(weChatRefundDto));
    }


}
